#region The MIT License
// The MIT License
// 
// Copyright (c) 2009 octalforty studios
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#endregion
using System;
using System.IO;
using System.Reflection;
using System.Xml;

using NUnit.Framework;

using octalforty.Componento.ComponentModel.Installation;
using octalforty.Componento.Shared.SemanticModel;

namespace octalforty.Componento.Tests.Componento.ComponentModel.Installation
{
    [TestFixture()]
    public class ComponentManifestParserTestFixture
    {
        [Test()]
        public void ParseComponentManifest()
        {
            XmlDocument xmlDocument = new XmlDocument();
            
            using(Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("octalforty.Componento.Tests.Manifest.xml"))
                xmlDocument.Load(stream);

            ComponentManifestParser componentManifestParser = new ComponentManifestParser();
            ComponentManifest manifest = componentManifestParser.ParseComponentManifest(xmlDocument);

            Assert.AreEqual(
                new ComponentDescriptor("NUnit", new Version(2, 5, 0, 9122),
                    null, new Uri("http://www.nunit.org"), new Uri("http://www.nunit.org/favicon.ico"),
                    "NUnit is a unit-testing framework for all .NET languages.",
                    new CliEnvironment[]
                        {
                            new CliEnvironment(CliType.NetFramework, new Version(1, 1)),
                            new CliEnvironment(CliType.NetFramework, new Version(2, 0))
                        },
                    new IsaType[] { IsaType.Cil },
                    new string[] { "zlib/libpng" }),
                manifest.Descriptor);

            Assert.AreEqual(1, manifest.Resources.Count);

            Assert.AreEqual(
                new Resource(new Uri("http://sourceforge.net/projects/nunit/files/NUnit Version 2/NUnit-2.5.0.9122.zip"), 2604530),
                manifest.Resources[0]);

            Assert.AreEqual(2, manifest.PathMappings.Count);

            Assert.AreEqual(new CliEnvironment(CliType.NetFramework, new Version(1, 1)), manifest.PathMappings[0].Cli);
            Assert.AreEqual("~/bin/net-1.1", manifest.PathMappings[0][PathMappingTarget.Binaries]);
            Assert.AreEqual("~/doc", manifest.PathMappings[0][PathMappingTarget.Documentation]);
            Assert.AreEqual("~/src", manifest.PathMappings[0][PathMappingTarget.Source]);

            Assert.AreEqual(new CliEnvironment(CliType.NetFramework, new Version(2, 0)), manifest.PathMappings[1].Cli);
            Assert.AreEqual("~/bin/net-2.0", manifest.PathMappings[1][PathMappingTarget.Binaries]);
            Assert.AreEqual("~/doc", manifest.PathMappings[1][PathMappingTarget.Documentation]);
            Assert.AreEqual("~/src", manifest.PathMappings[1][PathMappingTarget.Source]);
            Assert.AreEqual("~/samples", manifest.PathMappings[1][PathMappingTarget.Examples]);

            Assert.AreEqual(new ComponentReference("System.Core", new Version(3, 5),
                new Uri("componento+http://repository.componento.net")), manifest.Dependencies[0]);
        }
    }
}
